from django.forms.util import flatatt
from django.forms.widgets import TimeInput
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe

__author__ = 'Sharp'



class RichTimeInput(TimeInput):
    def __init__(self, *args, **kwargs):
        TimeInput.__init__(self, *args, **kwargs)

    __extra_html = """
        <a class='fillOnClick' fillingEntityId='%(id)s' fillingValue='0:10'>10min</a>
        <a class='fillOnClick' fillingEntityId='%(id)s' fillingValue='0:30'>30min</a>
        <a class='fillOnClick' fillingEntityId='%(id)s' fillingValue='1:00'>1hr</a>
        <a class='fillOnClick' fillingEntityId='%(id)s' fillingValue='1:30'>1.5hr</a>
        <a class='fillOnClick' fillingEntityId='%(id)s' fillingValue='2:00'>2hr</a>
        <a class='fillOnClick' fillingEntityId='%(id)s' fillingValue='3:00'>3hr</a>
    """

    def render(self, name, value, attrs=None):
        if value is None:
            value = ''
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value != '':
            # Only add the 'value' attribute if a value is non-empty.
            final_attrs['value'] = force_unicode(self._format_value(value))
        extra = self.__extra_html % {'id':attrs['id']}
        return mark_safe(u'<input%s />%s' % (flatatt(final_attrs), extra))